<?php

Raise::load('core.helper.convert.RaiseUnitConverter');

/**
 * RaiseAngleConverter class
 * for conversion between radian and degree angles
 * 
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package phpraise.core.helper.convert.unit
 * @since 1.2
 */
class RaiseAngleConverter extends RaiseUnitConverter {
    
    /**
     * Degree Unit
     */
    const DEGREE = 0;
    
    /**
     * Radian Unit
     */
    const RADIAN = 1;
    
    /**
     * Convert the subject between radian and degree
     * @param double $subject
     * @return double 
     */
    public function convert($subject) {
        $value = $subject;
        if($this->to() == self::RADIAN){
            $value = self::degreeToRadian($value);
        }else{
            $value = self::radianToDegree($value);
        }
        return $value;
    }
    
    /**
     * Convert degree to radian
     * @param double $degree
     * @return double
     */
    private static function degreeToRadian($degree){
        return deg2rad($degree);
    }
    
    /**
     * Convert radian to degree
     * @param double $radian
     * @return double
     */
    private static function radianToDegree($radian){
        return rad2deg($radian);
    }
    
}